define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                    extend: {
                        index_url: 'otc/otcorder/index',
                        edit_url: 'otc/otcorder/edit',
                        del_url: 'otc/otcorder/del',
                        multi_url: 'otc/otcorder/multi',
                        table: 'otcorder',
                    }
                },

                //设置flag样式
                // {
                //     custom:{"支付宝": 'info', "微信":'danger', "银联":'success'}
                // }


            );
            /*var state = {
                1: __('待交易'),
                2: __('待付款'),
                3: __('待确认'),
                4: __('已完成'),
                10: __('申述中'),
                20: __('已取消'),
                30: __('已撤单'),
            }*/

            $.getJSON({url: "otc/otcorder/otc_order_info", async:false, success: function(obj){
                    state = obj.state;
                    operation = obj.operation;
                    type = obj.type;
                    paytype = obj.paytype;
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'tradesn', title: __('Tradesn')},
                        {field: 'zoid', title: __('主订单ID')},
                        {field: 'uuname', title: __('Uuname')},
                        {field: 'uprice', title: __('Uprice'), operate:'BETWEEN'},
                        {field: 'amount1_total', title: __('总支付数量'), operate:'BETWEEN'},
                        {field: 'total_amount', title: __('总交易数量'), operate:'BETWEEN'},
                        {field: 'totalprice', title: __('总价格'), operate:'BETWEEN'},
                        {field: 'remain_amount', title: __('剩余数量'), operate:'BETWEEN'},
                        {field: 'minimum', title: __('最低限额'), operate:'BETWEEN'},
                        {field: 'amount1', title: __('支付数量'), operate:'BETWEEN'},
                        {field: 'amount2', title: __('交易数量'), operate:'BETWEEN'},
                        {field: 'servicecharge', title: __('Servicecharge'), operate:'BETWEEN'},
                        {field: 'price', title: __('价格'), operate:'BETWEEN'},
                        {field: 'buname', title: __('Buname')},
                        // {index: 'success', hot: 'warning', recommend: 'danger', 'new': 'info'}

                        {field: 'paytype', title: __('Paytype'), searchList: paytype},
                        {field: 'payproof', title: __('Payproof'), formatter:Table.api.formatter.image},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'ordertime', title: __('Ordertime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'paytime', title: __('Paytime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'dealtime', title: __('Dealtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'type', title: __('Type'), formatter: Table.api.formatter.status,searchList: type},

                        {field: 'state', title: __('State'), formatter: Table.api.formatter.status, searchList: state},
                        {field: 'operation', title: __('方式'), searchList: operation,formatter:function(value){
                                if (value == '0') {
                                    return '-';
                                }else {
                                    return operation[value];
                                }
                            }},
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });


            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});